package cn.dhn_app.util;

import org.springframework.stereotype.Component;
import sun.misc.BASE64Encoder;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Random;

/**
 * @Author lyy
 * @Description TODO
 * @PACKAGE_NAME: cn.dhn_app.util
 * @ClassName Token
 * @Date 2020/8/13 8:03
 * @DAY_NAME_FULL: 星期四
 * @Version 1.0
 **/

@Component
public class tokenTool {

    /**
     * 功能描述: <br>
     * 〈生成token〉
     * @Author: lyy
     * @Date: 2020/8/13 8:05
     * @Param: []
     * @Return: java.lang.String
     */
    public String makeToken() {

        String token = (System.currentTimeMillis() + new Random().nextInt(999999999)) + "";

        try {

            MessageDigest md = MessageDigest.getInstance("md5");

            byte md5[] =  md.digest(token.getBytes());

            BASE64Encoder encoder = new BASE64Encoder();

            return encoder.encode(md5);

        } catch (NoSuchAlgorithmException e) {

            // TODO Auto-generated catch block

            e.printStackTrace();

        }

        return null;

    }
}
